/*
 * @Author: lt
 * @Date: 2021-10-25 17:19:59
 * @Last Modified by: zy
 * @Last Modified time: 2021-10-25 17:20:42
 */

import { request } from 'umi';

type LoginParamsType = {
  phone: string;
  password: string;
  imageCode: string;
  imageCodeKey: string;
};

export type ImageCodeType = {
  imageCodeKey: string;
  imageCodeBase64: string;
};

// 1. 获取图片验证码
export async function getImageCode() {
  return request<{
    code: number;
    message: string;
    data: { imageCodeKey: string; imageCodeBase64: string };
  }>(`/loginManage/getImageCode`);
}

// 2. 登录
export async function login(body: LoginParamsType) {
  return request<{
    code: number;
    message: string;
    data: { token: string; name: string };
  }>(`/loginManage/userLogin`, {
    body: JSON.stringify(body),
    method: 'post',
  });
}

//3.
export async function getcurrentUser() {
  return request<{
    code: number;
    message: string;
    data: { name: string };
  }>(`/getCurrentUserInfo`, {
    method: 'GET',
  });
}
